<?php 
/**
* @package YaForms
* @copyright Авторские права (C) 2009 www.yar-it.com. Все права защищены.
* @license Лицензия http://www.gnu.org/licenses/gpl-2.0.htm GNU/GPL, или help/license.php
* YaForms! - свободное программное обеспечение распространяемое по условиям лицензии GNU/GPL
* Для получения информации о используемых расширениях и замечаний об авторском праве, смотрите файл copyright.php.
*/

defined( '_VALID_MOS' ) or die( 'Restricted access' );

function com_install() {

   global $database, $mosConfig_lang;
   require(JPATH_BASE.'/administrator/components/com_yaforms/lib/af.lib.core.php');
   afLoadLang();

   echo '<table border="0" cellspacing="0" cellpadding="0" width="75%" style="font-family:Arial;font-size:11px;color:#555;">
            <tr>
               <td valign="top">
                  <p><br /><strong>'.YAF_INST_TEXT1.'</strong></p>
                  <p>'.YAF_INST_TEXT2.'</p>
                  <p>'.YAF_INST_TEXT3.'</p>
               </td>
            </tr>
            <tr>
               <td valign="top" colspan="2">
                  <p>'.YAF_INST_TEXT5.'</p>
               </td>
            </tr>
         </table><br /><br />';

   if(!file_exists(JPATH_BASE.'/images/yaforms/asterisks/ast01.png') && file_exists(JPATH_BASE.'/components/com_yaforms/images/temp/ast01.png')) {
      $cdir1 = YAF_INST_CREATEDIR.' \'images/yaforms\'';
      if (@mkdir (JPATH_BASE."/images/yaforms", 0766) || is_dir(JPATH_BASE."/images/yaforms")) {
    	   @chmod (JPATH_BASE."/images/yaforms", 0766);
	   $cdirtask1 = '<font color=\'green\'>'.YAF_INST_CREATEDIRSUCC.'</font>';

	   $cdir2 = YAF_INST_CREATEDIR.' \'images/yaforms/attachedfiles\'';
	   if (@mkdir (JPATH_BASE."/images/yaforms/attachedfiles", 0766) || is_dir(JPATH_BASE."/images/yaforms/attachedfiles")) {
    	      @chmod (JPATH_BASE."/images/yaforms/attachedfiles", 0766);
    	      $cdirtask2 = '<font color=\'green\'>'.YAF_INST_CREATEDIRSUCC.'</font>';
	   } else {
	      $cdirtask2 = '<font color=\'red\'><strong>'.YAF_INST_CREATEDIRFAIL.': '.JPATH_BASE.'/images/yaforms/attachedfiles</strong></font>';
	   }

	   $cdir3 = YAF_INST_CREATEDIR.' \'images/yaforms/asterisks\'';
	   if (@mkdir (JPATH_BASE."/images/yaforms/asterisks", 0766) || is_dir(JPATH_BASE."/images/yaforms/asterisks")) {
    	      @chmod (JPATH_BASE."/images/yaforms/asterisks", 0766);
    	      $cdirtask3 = '<font color=\'green\'>'.YAF_INST_CREATEDIRSUCC.'</font>';
	   } else {
	      $cdirtask3 = '<font color=\'red\'><strong>'.YAF_INST_CREATEDIRFAIL.': '.JPATH_BASE.'/images/yaforms/asterisks</strong></font>';
	   }

           afCopyImgTmp( 'ast08.png' );

           afDelImgTmp( 'ast08.png' );

           afDelDirTmp( 'temp');

           echo $cdirtask1.'<br />';
           echo $cdirtask2.'<br />';
           echo $cdirtask3.'<br />';

      }

      echo "<br /><hr />";

      if( is_dir(JPATH_BASE.'/images/yaforms/') && is_dir(JPATH_BASE.'/images/yaforms/asterisks/') && is_dir(JPATH_BASE.'/images/yaforms/attachedfiles/') ) {
         chmod (JPATH_BASE."/images/yaforms/", 0755);
         chmod (JPATH_BASE."/images/yaforms/asterisks/", 0755);
         chmod (JPATH_BASE."/images/yaforms/attachedfiles/", 0755);
         $updmsg = '<font color=green>
                       <strong>'.YAF_UPD_DIRCHMSUCC.'
                       <br />'.JPATH_BASE.'/images/yaforms/
                       <br />'.JPATH_BASE.'/images/yaforms/asterisks/
                       <br />'.JPATH_BASE.'/images/yaforms/attachedfiles/
                       </strong>
                    </font><br /><br />';
      } else {
         $updmsg = '<font color=green>
                       <strong>'.YAF_UPD_DIRCHMERROR.'
                       <br />'.JPATH_BASE.'/images/yaforms/
                       <br />'.JPATH_BASE.'/images/yaforms/asterisks/
                       <br />'.JPATH_BASE.'/images/yaforms/attachedfiles/
                       </strong>
                    </font><br /><br />';
      }
      echo $updmsg;
      
      echo ('<table border="0" cellspacing="0" cellpadding="0" width="75%">'
	        .'<tr><td align="center">'
	        .'<p style="font-size:18px;color:green;">'.YAF_INST_MESS.'</p>'
                .'</td></tr></table><br /><br />');

   } else {
	
           echo "<br /><hr />";

	   
           echo ('<font color="red" style="font-size:18px;><strong>'.'&nbsp;'.YAF_INST_CREATEDIRFAIL.'</strong></font></p>'
	       . '<table border="0" cellspacing="0" cellpadding="0" background="'.JPATH_SITE.'/administrator/components/com_yaforms/images/logoyaforms.jpg" style="background-repeat:no-repeat; background-position:top right;" width="75%">'
	       . '<tr><td align="left">'
	       . '<p style="font-size:12px;"><strong>'.YAF_INST_MESSFAIL1.'</strong></p>'
	       . '<p style="font-size:12px;>'.YAF_INST_MESSFAIL2.'</p>'
	       . '<p style="font-size:12px;>'.YAF_INST_MESSFAIL3.'</p'
	       . '</td></tr></table><br /><br /><br /><br />');
   }
   
   
   $update = "UPDATE #__components SET `params` = 'rootfronttitle=YaForms\nfronttext=Выберите форму' WHERE link = 'option=com_yaforms' AND parent = '0'";
   $database->setQuery($update);
   $database->query();
   
   //добавляем кнопки в менюшку
   
   	  $database->setQuery("UPDATE #__components SET `name` = '".YAF_MENU_FORMS."', `admin_menu_alt` = '".YAF_MENU_FORMS."', admin_menu_img='../administrator/components/com_yaforms/images/forms16.png' WHERE admin_menu_link='option=com_yaforms&task=showaf'");
      $iconresult[0] = $database->query();
      $database->setQuery("UPDATE #__components SET `name` = '".YAF_MENU_RFORMS."', `admin_menu_alt` = '".YAF_MENU_RFORMS."', admin_menu_img='../administrator/components/com_yaforms/images/rforms16.png' WHERE admin_menu_link='option=com_yaforms&task=rforms'");
      $iconresult[1] = $database->query();
      $database->setQuery("UPDATE #__components SET `name` = '".YAF_MENU_HELP."', `admin_menu_alt` = '".YAF_MENU_HELP."', admin_menu_img='../administrator/components/com_yaforms/images/help16.png' WHERE admin_menu_link='option=com_yaforms&task=help'");
      $iconresult[2] = $database->query();
      $database->setQuery("UPDATE #__components SET `name` = '".YAF_MENU_LANG."', `admin_menu_alt` = '".YAF_MENU_LANG."', admin_menu_img='../administrator/components/com_yaforms/images/lang16.png' WHERE admin_menu_link='option=com_yaforms&task=language'");
      $iconresult[3] = $database->query();
      $database->setQuery("UPDATE #__components SET `name` = '".YAF_MENU_CSS."', `admin_menu_alt` = '".YAF_MENU_CSS."', admin_menu_img='../administrator/components/com_yaforms/images/css16.png' WHERE admin_menu_link='option=com_yaforms&task=cssedit'");
      $iconresult[4] = $database->query();
      $database->setQuery("UPDATE #__components SET `name` = '".YAF_MENU_CONFIG."', `admin_menu_alt` = '".YAF_MENU_CONFIG."', admin_menu_img='../administrator/components/com_yaforms/images/config16.png' WHERE admin_menu_link='option=com_yaforms&task=config'");
      $iconresult[5] = $database->query();
      $database->setQuery("UPDATE #__components SET `name` = '".YAF_MENU_UPDATE."', `admin_menu_alt` = '".YAF_MENU_UPDATE."', admin_menu_img='../administrator/components/com_yaforms/images/update16.png' WHERE admin_menu_link='option=com_yaforms&task=update'");
      $iconresult[6] = $database->query();
      $database->setQuery("UPDATE #__components SET `name` = '".YAF_MENU_INFO."', `admin_menu_alt` = '".YAF_MENU_INFO."', admin_menu_img='../administrator/components/com_yaforms/images/info16.png' WHERE admin_menu_link='option=com_yaforms&task=info'");
      $iconresult[7] = $database->query();
      $database->setQuery("UPDATE #__components SET admin_menu_img='../administrator/components/com_yaforms/images/iconlogo.png' WHERE admin_menu_link='option=com_yaforms'");
      $iconresult[8] = $database->query();

}


?>
